package com.mycontract.suitepro.components.dialog

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.*
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import com.mycontract.suitepro.R
import com.mycontract.suitepro.base.BaseDialogAction
import com.mycontract.suitepro.databinding.DialogContractSuiteContractInputPhoneBinding
import com.mycontract.suitepro.extend.recordContractSuiteClickContractSuiteEvent

class ContractInputPhoneDialog : DialogFragment(), BaseDialogAction {

    //星级
    private var mRate = 0

    //显示文案
    private var mContent: String? = ""

    companion object {
        fun showContractSuiteDialog(
            fragmentManager: FragmentManager,
            listener: (String) -> Unit
        ) {
            val dialog = ContractInputPhoneDialog()
            dialog.mContractSuiteOnContractSuiteDialogContractSuiteConfirmContractSuiteListener = listener
            dialog.showNow(fragmentManager, ContractInputPhoneDialog::class.java.simpleName)
        }
    }

    lateinit var mContractSuiteViewContractSuiteBinding: DialogContractSuiteContractInputPhoneBinding
    var mContractSuiteOnContractSuiteDialogContractSuiteConfirmContractSuiteListener: (String) -> Unit = { }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?,
    ): View {
        dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE);
        mContractSuiteViewContractSuiteBinding =
            DialogContractSuiteContractInputPhoneBinding.inflate(layoutInflater)

        return mContractSuiteViewContractSuiteBinding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initContractSuiteSubviews()
        dialog?.setCancelable(true)
        dialog?.setCanceledOnTouchOutside(true)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setStyle(STYLE_NO_TITLE, R.style.Dialog)
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun onStart() {
        super.onStart()

        dialog?.window?.let {
            it.attributes.gravity = Gravity.CENTER
            it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
//            it.setWindowAnimations(R.style.bottomDialogAnimation)
        }

    }

    override fun initContractSuiteSubviews() {
        try {
            mContractSuiteViewContractSuiteBinding.textContractInputPhoneRate.setOnClickListener {
                mContractSuiteViewContractSuiteBinding.textContractInputPhoneRate.recordContractSuiteClickContractSuiteEvent()

                val content =
                    mContractSuiteViewContractSuiteBinding.editContractInputPhone.text.toString().trim()
                if (content.isBlank()) {

                } else {
                    mContractSuiteOnContractSuiteDialogContractSuiteConfirmContractSuiteListener.invoke(content)
                    dismiss()
                }
            }

            mContractSuiteViewContractSuiteBinding.imageDialogContractInputPhoneClose.setOnClickListener {
                dismiss()
            }
        } catch (e: Exception) {
            e.printStackTrace()
        }
    }

    override fun showContractSuiteWithContractSuiteUIContractSuiteTag(
        gTag: String,
        fragmentManager: FragmentManager
    ) {
    }

    override fun setContractSuiteOnContractSuiteActionContractSuiteClickContractSuiteListener(listener: (Int) -> Unit) {
    }

}